#ifndef __SOCKET_H__
#define __SOCKET_H__

#include <string>

#define NOTE_SOCK_MAX 1024

/*-------------------------------------------------------------------
 * class
 *-------------------------------------------------------------------*/
template<typename T>
class SocketSer
{
    struct list_node
    {
        list_node  *next{nullptr};
        T*          sock_app;
    };

public:
    SocketSer(std::string ip, int port, int max):ip_{ip}, port_{port}, max_{max}{}
    SocketSer() = delete;
    ~SocketSer();

    bool init();
    void start();

private:
    void add_client(int fd);
    void del_client(int fd);
    T* get_client_sock(int fd);

    bool reactor_list_init();
    bool resize_list();

private:
    int             sock_fd_{};
    int             epol_fd_{};
    std::string     ip_{};
    int             port_{};
    int             max_{};
private:
    list_node      *sock_app{};
    int             node_cnt{};
};

#include <core/socket.hpp>
#endif